package com.example.administrator.idocment.docment;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import com.example.administrator.idocment.BaseTypeFind;
import com.example.administrator.idocment.msgpack.modelpack.ZipModel;
import com.example.administrator.idocment.tooltime.TimerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/15 0015.
 */
public class ZipFind extends BaseTypeFind<ZipModel> {

    public static final String[] zipType=new String[]{"application/x-gtar","application/x-gzip","application/x-compress","application/zip"};
    public ZipFind(Context context) {
        super(context);
    }

    List<ZipModel> zipModelList=new ArrayList<>();

    @Override
    public void select() {

        Uri uri= MediaStore.Files.getContentUri("external");
        String[] colums=new String[]{MediaStore.Files.FileColumns.DATA,MediaStore.Files.FileColumns.SIZE};
        String selection="";
        for(int i=0;i<zipType.length;i++)
        {
            if(i!=0)
            {
                selection+=" OR ";
            }
            selection = selection + MediaStore.Files.FileColumns.MIME_TYPE + " LIKE '%" + zipType[i] + "'";
        }
        String sort=MediaStore.Files.FileColumns.SIZE+" ASC";

        Cursor cursor= contentResolver.query(uri, colums, selection, null, sort);
        cursor.moveToFirst();
        do {
            String path=cursor.getString(0);

            File file=new File(path);
            String title=file.getName();
            String date= TimerFactory.create(TimerFactory.YearFormat).paseTimer(file.lastModified());
            String size=getFileSzie(cursor.getLong(1));

            ZipModel zipModel=new ZipModel();
            zipModel.setTitle(title);
            zipModel.setDate(date);
            zipModel.setSize(size);
            zipModel.setPath(path);

            zipModelList.add(zipModel);
        }while (cursor.moveToNext());


    }

    @Override
    public List<ZipModel> getListInfo() {


        return zipModelList;
    }





}
